import React, {Component, Fragment} from 'react';
import {Route, Switch, Redirect} from "react-router-dom";
import {adminRouter} from "./routes";
import Layout from  './components/Layout'
import { connect } from 'react-redux'

const mapStateToProps = (state,props) => {
    return {
        isManagerLogin : state.admin.isLogin
    }
}

@connect(mapStateToProps)
class App extends Component {
    componentDidMount() {
    }

    render() {
        return (
            <Fragment>
                {
                    this.props.isManagerLogin ? <Layout>
                        <Switch>
                            {
                                adminRouter.map(routes => {
                                    return <Route path={routes.pathname} key={routes.pathname} component={routes.component} exact></Route>
                                })
                            }
                            <Redirect to={adminRouter[0].pathname} from='/admin'></Redirect>
                        </Switch>
                    </Layout> : <Redirect to='/login'></Redirect>
                }
            </Fragment>
        );
    }
}

export default App;